﻿using System;

namespace Microsoft.Popfly.GameCreator.GameEngine.Events
{
    public class DisappearListener : EventListener
    {
        public DisappearListener(Game game, BehaviorOwner owner, Data.BehaviorInfo behaviorInfo) : base(game, owner, behaviorInfo)
        {
            if (behaviorInfo.Event.Type != "Disappear")
            {
                throw new ArgumentException(
                    Utils.ErrorMessagePrefix +
                    "DisappearListeners are only for disappear events.  Event type was '" +
                    behaviorInfo.Event.Type + "'."
                    );
            }

            if (!owner.IsActor)
            {
                throw new ArgumentException(
                    Utils.ErrorMessagePrefix +
                    "DisappearListeners are only for actors.");
            }
        }

        public void Raise()
        {
            if (!QueuedForRemoval)
            {
                if (Filter == null || Filter.CheckFilter())
                {
                    if (AudioUrl != null)
                    {
                        m_game.PlayAudio(AudioUrl);
                    }
                    Behavior.Invoke(Owner, null);
                }
            }
        }
    }
}
